package day16.test01;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Xiao
 * @date 2021/8/10
 */
public class ServerDemo {
    /**
     * 1. 将上课讲的网络编程案例：文件上传线程池最终版，实现一遍。
     */
    public static void main(String[] args) throws IOException {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                5,
                2,
                TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        ServerSocket ss = new ServerSocket(12321);
        while (true) {
            Socket so = ss.accept();
            ThreadSocket ts = new ThreadSocket(so);
            pool.submit(ts);
        }
    }
}
